home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-04d.zip / 04d / CHIP / Porady / Niewidoczny w sieci / TOR 0.1.2.7 / vidalia-bundle-0.1.2.7-alpha-0.0.10.exe / Tor / Documents / path-spec.txt < prev    next >
Text File  |  2007-02-07  |  18KB  |  375 lines

  1. $Id: path-spec.txt 9491 2007-02-06 00:27:03Z arma $
  2.  
  3.                            Tor Path Specification
  4.  
  5.                               Roger Dingledine
  6.                                Nick Mathewson
  7.  
  8. Note: This is an attempt to specify Tor as currently implemented.  Future
  9. versions of Tor will implement improved algorithms.
  10.  
  11. This document tries to cover how Tor chooses to build circuits and assign
  12. streams to circuits.  Other implementations MAY take other approaches, but
  13. implementors should be aware of the anonymity and load-balancing implications
  14. of their choices.
  15.  
  16.                     THIS SPEC ISN'T DONE OR CORRECT YET.
  17.  
  18. 1. General operation
  19.  
  20.    Tor begins building circuits as soon as it has enough directory
  21.    information to do so (see section 5.1 of dir-spec.txt).  Some circuits are
  22.    built preemptively because we expect to need them later (for user
  23.    traffic), and some are built because of immediate need (for user traffic
  24.    that no current circuit can handle, for testing the network or our
  25.    reachability, and so on).
  26.  
  27.    When a client application creates a new stream (by opening a SOCKS
  28.    connection or launching a resolve request), we attach it to an appropriate
  29.    open circuit if one exists, or wait if an appropriate circuit is
  30.    in-progress. We launch a new circuit only
  31.    if no current circuit can handle the request.  We rotate circuits over
  32.    time to avoid some profiling attacks.
  33.  
  34.    To build a circuit, we choose all the nodes we want to use, and then
  35.    construct the circuit.  Sometimes, when we want a circuit that ends at a
  36.    given hop, and we have an appropriate unused circuit, we "cannibalize" the
  37.    existing circuit and extend it to the new terminus.
  38.  
  39.    These processes are described in more detail below.
  40.  
  41.    This document describes Tor's automatic path selection logic only; path
  42.    selection can be overridden by a controller (with the EXTENDCIRCUIT and
  43.    ATTACHSTREAM commands).  Paths constructed through these means may
  44.    violate some constraints given below.
  45.  
  46. 1b. Terminology
  47.  
  48.    A "path" is an ordered sequence of nodes, not yet built as a circuit.
  49.  
  50.    A "clean" circuit is one that has not yet been used for any traffic.
  51.  
  52.    A "fast" or "stable" or "valid" node is one that has the 'Fast' or
  53.    'Stable' or 'Valid' flag
  54.    set respectively, based on our current directory information.  A "fast"
  55.    or "stable" circuit is one consisting only of "fast" or "stable" nodes.
  56.  
  57.    In an "exit" circuit, the final node is chosen based on waiting stream
  58.    requests if any, and in any case it avoids nodes with exit policy of
  59.    "reject *:*". An "internal" circuit, on the other hand, is one where
  60.    the final node is chosen just like a middle node (ignoring its exit
  61.    policy).
  62.  
  63.    A "request" is a client-side stream or DNS resolve that needs to be
  64.    served by a circuit.
  65.  
  66.    A "pending" circuit is one that we have started to build, but which has
  67.    not yet completed.
  68.  
  69.    A circuit or path "supports" a request if it is okay to use the
  70.    circuit/path to fulfill the request, according to the rules given below.
  71.    A circuit or path "might support" a request if some aspect of the request
  72.    is unknown (usually its target IP), but we believe the path probably
  73.    supports the request according to the rules given below.
  74.  
  75. 2. Building circuits
  76.  
  77. 2.1. When we build.
  78.  
  79. 2.1.1. Clients build circuits preemptively
  80.  
  81.    When running as a client, Tor tries to maintain at least a certain
  82.    number of clean circuits, so that new streams can be handled
  83.    quickly.  To increase the likelihood of success, Tor tries to
  84.    predict what circuits will be useful by choosing from among nodes
  85.    that support the ports we have used in the recent past (by default
  86.    one hour). Specifically, on startup Tor tries to maintain one clean
  87.    fast exit circuit that allows connections to port 80, and at least
  88.    two internal circuits in case we get a resolve request or hidden
  89.    service request (at least three internal circuits if we _run_ a
  90.    hidden service).
  91.  
  92.    After that, Tor will adapt the circuits that it preemptively builds
  93.    based on the requests it sees from the user: it tries to have a clean
  94.    fast exit circuit available for every port seen recently (one circuit
  95.    is adequate for many predicted ports -- it doesn't keep a separate
  96.    circuit for each port), and it tries to have the above internal
  97.    circuits available if we've seen resolves or hidden service activity
  98.    recently. If there are 12 clean circuits open, it doesn't open more
  99.    even if it has more predictions. Lastly, note that if there are no
  100.    requests from the user for an hour, Tor will predict no use and build
  101.    no preemptive circuits.
  102.  
  103.    The Tor client SHOULD NOT store its list of predicted requests to a
  104.    persistent medium.
  105.  
  106. 2.1.2. Clients build circuits on demand
  107.  
  108.    Additionally, when a client request exists that no circuit (built or
  109.    pending) might support, we create a new circuit to support the request.
  110.    We do so by picking a request arbitrarily, launching a circuit to
  111.    support it, and repeating until every unattached request might be
  112.    supported by a pending or built circuit.
  113.  
  114.    For hidden service interations, we can "cannibalize" a clean internal
  115.    circuit if one is available, so we don't need to build those circuits
  116.    from scratch on demand.
  117.  
  118.    We can also cannibalize clean circuits when the client asks to exit
  119.    at a given node -- either via mapaddress or the ".exit" notation,
  120.    or because the destination is running at the same location as an
  121.    exit node.
  122.  
  123. 2.1.3. Servers build circuits for testing reachability
  124.  
  125.    Tor servers test reachability of their ORPort on start and whenever
  126.    their IP address changes.
  127.    XXXX
  128.  
  129. 2.1.4. Hidden-service circuits
  130.  
  131.    See section 4 below.
  132.  
  133. 2.1.5. Rate limiting of failed circuits
  134.  
  135.    If we fail to build a circuit N times in a X second period (see Section
  136.    2.3 for how this works), we stop building circuits until the X seconds
  137.    have elapsed.
  138.    XXXX
  139.  
  140. 2.1.6. When to tear down circuits
  141.  
  142.    XXXX
  143.  
  144. 2.2. Path selection and constraints
  145.  
  146.    We choose the path for each new circuit before we build it.  We choose the
  147.    exit node first, followed by the other nodes in the circuit.  All paths
  148.    we generate obey the following constraints:
  149.      - We do not choose the same router twice for the same path.
  150.      - We do not choose any router in the same family as another in the same
  151.        path.
  152.      - We do not choose more than one router in a given /16 subnet
  153.        (unless EnforceDistinctSubnets is 0).
  154.      - We don't choose any non-running or non-valid router unless we have
  155.        been configured to do so. By default, we are configured to allow
  156.        non-valid routers in "middle" and "rendezvous" positions.
  157.      - If we're using Guard nodes, the first node must be a Guard (see 5
  158.        below)
  159.      - XXXX Choosing the length
  160.  
  161.    For circuits that do not need to be not "fast", when choosing among
  162.    multiple candidates for a path element, we choose randomly.
  163.  
  164.    For "fast" circuits, we pick a given router as an exit with probability
  165.    proportional to its advertised bandwidth [the smaller of the 'rate' and
  166.    'observed' arguments to the "bandwidth" element in its descriptor].  If a
  167.    router's advertised bandwidth is greater than MAX_BELIEVABLE_BANDWIDTH
  168.    (1.5 MB/s), we clip to that value.
  169.  
  170.    For non-exit positions on "fast" circuits, we pick routers as above, but
  171.    we weight the clipped advertised bandwidth of Exit-flagged nodes depending
  172.    on the fraction of bandwidth available from non-Exit nodes.  Call the
  173.    total clipped advertised bandwidth for Exit nodes under consideration E,
  174.    and the total clipped advertised bandwidth for non-Exit nodes under
  175.    consideration N.  If E<N/2, we do not consider Exit-flagged nodes.
  176.    Otherwise, we weight their bandwidth with the factor (E-N/2)/(N+E-N/2) ==
  177.    (2E - N)/(2E + N).  This ensures that bandwidth is evenly distributed over
  178.    nodes in 3-hop paths.
  179.  
  180.    Additionally, we may be building circuits with one or more requests in
  181.    mind.  Each kind of request puts certain constraints on paths:
  182.  
  183.      - All service-side introduction circuits and all rendezvous paths
  184.        should be Stable.
  185.      - All connection requests for connections that we think will need to
  186.        stay open a long time require Stable circuits.  Currently, Tor decides
  187.        this by examining the request's target port, and comparing it to a
  188.        list of "long-lived" ports. (Default: 21, 22, 706, 1863, 5050,
  189.        5190, 5222, 5223, 6667, 6697, 8300.)
  190.      - DNS resolves require an exit node whose exit policy is not equivalent
  191.        to "reject *:*".
  192.      - Reverse DNS resolves require a version of Tor with advertised eventdns
  193.        support (available in Tor 0.1.2.1-alpha-dev and later).
  194.      - All connection requests require an exit node whose exit policy
  195.        supports their target address and port (if known), or which "might
  196.        support it" (if the address isn't known).  See 2.2.1.
  197.      - Rules for Fast? XXXXX
  198.  
  199. 2.2.1. Choosing an exit
  200.  
  201.    If we know what IP address we want to resolve, we can trivially tell
  202.    whether a given router will support it by simulating its declared
  203.    exit policy.
  204.  
  205.    Because we often connect to addresses of the form hostname:port, we do not
  206.    always know the target IP address when we select an exit node.  In these
  207.    cases, we need to pick an exit node that "might support" connections to a
  208.    given address port with an unknown address.  An exit node "might support"
  209.    such a connection if any clause that accepts any connections to that port
  210.    precedes all clauses (if any) that reject all connections to that port.
  211.  
  212.    Unless requested to do so by the user, we never choose an exit server
  213.    flagged as "BadExit" by more than half of the authorities who advertise
  214.    themselves as listing bad exits.
  215.  
  216. 2.2.2. User configuration
  217.  
  218.    Users can alter the default behavior for path selection with configuration
  219.    options.
  220.  
  221.    - If "ExitNodes" is provided, then every request requires an exit node on
  222.      the ExitNodes list.  (If a request is supported by no nodes on that list,
  223.      and StrictExitNodes is false, then Tor treats that request as if
  224.      ExitNodes were not provided.)
  225.  
  226.    - "EntryNodes" and "StrictEntryNodes" behave analogously.
  227.  
  228.    - If a user tries to connect to or resolve a hostname of the form
  229.      <target>.<servername>.exit, the request is rewritten to a request for
  230.      <target>, and the request is only supported by the exit whose nickname
  231.      or fingerprint is <servername>.
  232.  
  233. 2.3. Handling failure
  234.  
  235.    If an attempt to extend a circuit fails (either because the first create
  236.    failed or a subsequent extend failed) then the circuit is torn down and is
  237.    no longer pending.  (XXXX really?)  Requests that might have been
  238.    supported by the pending circuit thus become unsupported, and a new
  239.    circuit needs to be constructed.
  240.  
  241.    If a stream "begin" attempt fails with an EXITPOLICY error, we
  242.    decide that the exit node's exit policy is not correctly advertised,
  243.    so we treat the exit node as if it were a non-exit until we retrieve
  244.    a fresh descriptor for it.
  245.  
  246.    XXXX
  247.  
  248. 3. Attaching streams to circuits
  249.  
  250.    When a circuit that might support a request is built, Tor tries to attach
  251.    the request's stream to the circuit and sends a BEGIN or RESOLVE relay
  252.    cell as appropriate.  If the request completes unsuccessfully, Tor
  253.    considers the reason given in the CLOSE relay cell. [XXX yes, and?]
  254.  
  255.  
  256.    After a request has remained unattached for [XXXX interval?], Tor
  257.    abandons the attempt and signals an error to the client as appropriate
  258.    (e.g., by closing the SOCKS connection).
  259.  
  260.    XXX Timeouts and when Tor auto-retries.
  261.     * What stream-end-reasons are appropriate for retrying.
  262.  
  263.    If no reply to BEGIN/RESOLVE, then the stream will timeout and fail.
  264.  
  265. 4. Hidden-service related circuits
  266.  
  267.   XXX Tracking expected hidden service use (client-side and hidserv-side)
  268.  
  269. 5. Guard nodes
  270.  
  271.   We use Guard nodes (also called "helper nodes" in the literature) to
  272.   prevent certain profiling attacks.  Here's the risk: if we choose entry and
  273.   exit nodes at random, and an attacker controls C out of N servers
  274.   (ignoring advertised bandwidth), then the
  275.   attacker will control the entry and exit node of any given circuit with
  276.   probability (C/N)^2.  But as we make many different circuits over time,
  277.   then the probability that the attacker will see a sample of about (C/N)^2
  278.   of our traffic goes to 1.  Since statistical sampling works, the attacker
  279.   can be sure of learning a profile of our behavior.
  280.  
  281.   If, on the other hand, we picked an entry node and held it fixed, we would
  282.   have probability C/N of choosing a bad entry and being profiled, and
  283.   probability (N-C)/N of choosing a good entry and not being profiled.
  284.  
  285.   When guard nodes are enabled, Tor maintains an ordered list of entry nodes
  286.   as our chosen guards, and store this list persistently to disk.  If a Guard
  287.   node becomes unusable, rather than replacing it, Tor adds new guards to the
  288.   end of the list.  When it comes time to choose an entry, Tor chooses at
  289.   random from among the first NumEntryGuards (default 3) usable guards on the
  290.   list.  If there are not at least 2 usable guards on the list, Tor adds
  291.   routers until there are, or until there are no more usable routers to add.
  292.  
  293.   A guard is unusable if any of the following hold:
  294.     - it is not marked as a Guard by the networkstatuses,
  295.     - it is not marked Valid (and the user hasn't set AllowInvalid entry)
  296.     - it is not marked Running
  297.     - Tor couldn't reach it the last time it tried to connect
  298.  
  299.   A guard is unusable for a particular circuit if any of the rules for path
  300.   selection in 2.2 are not met.  In particular, if the circuit is "fast"
  301.   and the guard is not Fast, or if the circuit is "stable" and the guard is
  302.   not Stable, or if the guard has already been chosen as the exit node in
  303.   that circuit, Tor can't use it as a guard node for that circuit.
  304.  
  305.   If the guard is excluded because of its status in the networkstatuses for
  306.   over 30 days, Tor removes it from the list entirely, preserving order.
  307.  
  308.   If Tor fails to connect to an otherwise usable guard, it retries
  309.   periodically: every hour for six hours, every 4 hours for 3 days, every
  310.   18 hours for a week, and every 36 hours thereafter.  Additionally, Tor
  311.   retries unreachable guards the first time it adds a new guard to the list,
  312.   since it is possible that the old guards were only marked as unreachable
  313.   because the network was unreachable or down.
  314.  
  315.   Tor does not add a guard persistently to the list until the first time we
  316.   have connected to it successfully.
  317.  
  318. 6. Testing circuits
  319.  
  320.   XXXX
  321.  
  322.  
  323.  
  324.  
  325. X. Old notes
  326.  
  327. X.1. Do we actually do this?
  328.  
  329. How to deal with network down.
  330.   - While all helpers are down/unreachable and there are no established
  331.     or on-the-way testing circuits, launch a testing circuit. (Do this
  332.     periodically in the same way we try to establish normal circuits
  333.     when things are working normally.)
  334.     (Testing circuits are a special type of circuit, that streams won't
  335.     attach to by accident.)
  336.   - When a testing circuit succeeds, mark all helpers up and hold
  337.     the testing circuit open.
  338.   - If a connection to a helper succeeds, close all testing circuits.
  339.     Else mark that helper down and try another.
  340.   - If the last helper is marked down and we already have a testing
  341.     circuit established, then add the first hop of that testing circuit
  342.     to the end of our helper node list, close that testing circuit,
  343.     and go back to square one. (Actually, rather than closing the
  344.     testing circuit, can we get away with converting it to a normal
  345.     circuit and beginning to use it immediately?)
  346.  
  347.   [Do we actually do any of the above?  If so, let's spec it.  If not, let's
  348.   remove it. -NM]
  349.  
  350. X.2. A thing we could do to deal with reachability.
  351.  
  352. And as a bonus, it leads to an answer to Nick's attack ("If I pick
  353. my helper nodes all on 18.0.0.0:*, then I move, you'll know where I
  354. bootstrapped") -- the answer is to pick your original three helper nodes
  355. without regard for reachability. Then the above algorithm will add some
  356. more that are reachable for you, and if you move somewhere, it's more
  357. likely (though not certain) that some of the originals will become useful.
  358. Is that smart or just complex?
  359.  
  360. X.3. Some stuff that worries me about entry guards. 2006 Jun, Nickm.
  361.  
  362.   It is unlikely for two users to have the same set of entry guards.
  363.   Observing a user is sufficient to learn its entry guards.  So, as we move
  364.   around, entry guards make us linkable.  If we want to change guards when
  365.   our location (IP? subnet?) changes, we have two bad options.  We could
  366.     - Drop the old guards.  But if we go back to our old location,
  367.       we'll not use our old guards.  For a laptop that sometimes gets used
  368.       from work and sometimes from home, this is pretty fatal.
  369.     - Remember the old guards as associated with the old location, and use
  370.       them again if we ever go back to the old location.  This would be
  371.       nasty, since it would force us to record where we've been.
  372.  
  373.   [Do we do any of this now? If not, this should move into 099-misc or
  374.   098-todo. -NM]
  375.